﻿<%@ Page Title="MembershipUser Details" Language="C#" MasterPageFile="~/Views/Shared/OneCol.Master" AutoEventWireup="true" CodeBehind="DisplayUser.aspx.cs" Inherits="StarterKits.Mvc.Membership.Views.FormsAuthenticationAdministration.DisplayUser" %>
<%@ Import Namespace="P.InOut.NetMvc.Models" %>

<asp:Content ID="Scripts" ContentPlaceHolderID="Scripts" runat="server">
<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.maskedinput.js" type="text/javascript"></script>

<script type="text/javascript">

    jQuery(function($) {

        $("#birthdate").mask("99/99/9999");
        $("#officePhone").mask("(999) 999-9999");
        $("#remotePhone").mask("(999) 999-9999");
    });
        
</script>
</asp:Content>

<asp:Content ID="content" ContentPlaceHolderID="Col1" runat="server">
<h2><% =ViewData.Model.User.UserName %></h2>

<% using( Html.Form( "FormsAuthenticationAdministration", "SaveExistingUser" ) ) { %>
<fieldset class="MvcMembership">    
	<legend>User Details</legend>

	<div>
	<label>User Name</label>
	<div><% =ViewData.Model.User.UserName %></div>
	<% =Html.Hidden( "UserName", ViewData.Model.User.UserName ) %>
	</div>

	<div>
	<label>Provider User Key</label>
	<div><% =ViewData.Model.User.ProviderUserKey %></div>
	</div>

	<div>
	<label for="MembershipUser.Email">Email Address</label>
	<% =Html.TextBox( "MembershipUser.Email", ViewData.Model.User.Email, new { maxLength="128" }) %>
	</div>

	<div>
	<label for="MembershipUser.Comment">Comment</label>
	<% =Html.TextBox( "MembershipUser.Comment", ViewData.Model.User.Comment, new { size = 32, maxlength = 256 } ) %>
	</div>

	<div>
	<label for="XMembershipUser.IsApproved">Is Approved</label>
	<div><input type="checkbox" id="XMembershipUser.IsApproved" name="XMembershipUser.IsApproved" <% =ViewData.Model.User.IsApproved ? "checked=\"checked\"" : "" %> /></div>
	</div>

	<hr />

	<div>
	<label>Created</label>
	<div><% =ViewData.Model.User.CreationDate.ToString( "M/d/yyyy h:mm:ss tt" )%></div>
	</div>

	<div>
	<label>Last Login</label>
	<div><% =ViewData.Model.User.CreationDate != ViewData.Model.User.LastLoginDate ? ViewData.Model.User.LastLoginDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Logged In" %></div>
	</div>

	<div>
	<label>Last Activity</label>
	<div><% =ViewData.Model.User.CreationDate != ViewData.Model.User.LastActivityDate ? ViewData.Model.User.LastActivityDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Active" %> (<% =ViewData.Model.User.IsOnline ? "Online" : "Offline" %>)</div>
	</div>

	<div>
	<label>Last Lockout</label>
	<div><% =( ViewData.Model.User.LastLockoutDate == DateTime.MinValue ? ViewData.Model.User.LastLockoutDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Locked Out" ) %></div>
	<% if( ViewData.Model.User.IsLockedOut ){ %>
	<div><% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x => x.UnlockUser( (Guid)ViewData.Model.User.ProviderUserKey ), "(Unlock User)" )%></div>
	<% } %>
	</div>

	<div><% =Html.SubmitButton( "Update User Details" ) %></div>

</fieldset>
<% } %>

<% using( Html.Form( "FormsAuthenticationAdministration", "UpdateUserProfile" ) ) { %>
<fieldset class="MvcMembership">
	<legend>User Profile</legend>
	
	<div>
	<% =Html.Hidden( "UserName", ViewData.Model.User.UserName ) %>
	<label for="firstName">First Name</label>
	<div><%= Html.TextBox( "firstname", ViewData.Model.Profile.FirstName == null ? string.Empty :
                ViewData.Model.Profile.FirstName) %></div>
	</div>
	
	<div>
	<label for="lastname">Last Name</label>
	<div><%= Html.TextBox( "lastname", ViewData.Model.Profile.LastName == null ? string.Empty :
                ViewData.Model.Profile.LastName) %></div>
	</div>

	<div>
	<label for="birthdate">Birthdate</label>
	<div><%= Html.TextBox( "birthdate", ViewData.Model.Profile.Birthdate == null ? string.Empty :
                ViewData.Model.Profile.Birthdate.Value.ToShortDateString()) %></div>
	</div>

	<div>
	<label for="officePhone">Office Phone</label>
	<div><%= Html.TextBox( "officePhone", 
	      ViewData.Model.Profile.OfficePhone)   %></div>
	</div>

	<div>
	<label for="remotePhone">Remote Phone</label>
	<div><%= Html.TextBox( "remotePhone", 
	    ViewData.Model.Profile.RemotePhone) %></div>
	</div>

	<div><%= Html.SubmitButton( "Update User Profile" ) %></div>

</fieldset>
<% } %>

<fieldset class="MvcMembership">
	<legend>User Teams</legend>
	
	<% if (ViewData.Model.AllTeams.Count > 0)
    { %>
        <% foreach (Team team in ViewData.Model.AllTeams)
        { %>
        
            <div>
                <% if (ViewData.Model.UsersTeams.Contains(team)) { %>
                    (<% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x => x.RemoveUserFromTeam( (Guid)ViewData.Model.User.ProviderUserKey, team.Description ), "-" )%>)
                <% }else{ %>
		            (<% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x => x.AddUserToTeam( (Guid)ViewData.Model.User.ProviderUserKey, team.Description ), "+" )%>)
		        <% } %>
		        <% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x=>x.Team(team.Description), team.Description ) %>
            </div>
        
        <% } %>	
	<% } %>

</fieldset>

<% if (ViewData.Model.RolesEnabled) { %>
<fieldset class="MvcMembership">
	<legend>Roles</legend>

	<% if( ViewData.Model.AllRoles.Count > 0 ){ %>
	<% foreach( string role in ViewData.Model.AllRoles ){ %>
	<div>
		<% if( ViewData.Model.UsersRoles.Contains(role) ){ %>
		(<% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x => x.RemoveUserFromRole( (Guid)ViewData.Model.User.ProviderUserKey, role ), "-" )%>)
		<% }else{ %>
		(<% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x => x.AddUserToRole( (Guid)ViewData.Model.User.ProviderUserKey, role ), "+" )%>)
		<% } %>
		<% =Html.ActionLink<P.InOut.NetMvc.Controllers.FormsAuthenticationAdministrationController>( x=>x.Role(role), role ) %>
	</div>
	<% } %>
	<% }else{ %>
	<div>No roles have been added to the system yet.</div>
	<% } %>
</fieldset>
<% } %>

<% using( Html.Form( "FormsAuthenticationAdministration", "ResetPassword" ) ){ %>
<fieldset class="MvcMembership">
	<legend>Reset Password</legend>

	<% =Html.Hidden( "UserName", ViewData.Model.User.UserName ) %>

	<div>
	<label>Last Password Change</label>
	<div><% =ViewData.Model.User.CreationDate != ViewData.Model.User.LastPasswordChangedDate ? ViewData.Model.User.LastPasswordChangedDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Changed Password" %></div>
	</div>

	<div>
	<label>Password Question</label>
	<div><% =ViewData.Model.User.PasswordQuestion %></div>
	</div>

	<div>
	<label for="PasswordAnswer">Password Answer</label>
	<% =Html.TextBox("PasswordAnswer", new { size = 32, maxlength = 128 })%>
	</div>

	<div><% =Html.SubmitButton( "Reset Password" ) %></div>

</fieldset>
<% } %>

<% using( Html.Form( "FormsAuthenticationAdministration", "ChangePassword" ) ){ %>
<fieldset class="MvcMembership">
	<legend>Change Password</legend>

	<% =Html.Hidden( "UserName", ViewData.Model.User.UserName ) %>

	<div>
	<label>Last Password Change</label>
	<div><% =ViewData.Model.User.CreationDate != ViewData.Model.User.LastPasswordChangedDate ? ViewData.Model.User.LastPasswordChangedDate.ToString( "M/d/yyyy h:mm:ss tt" ) : "Never Changed Password" %></div>
	</div>

	<div>
	<label for="OldPassword">Old Password</label>
	<% =Html.Password( "OldPassword", new { size = 32 } ) %>
	</div>

	<div>
	<label for="NewPassword">New Password</label>
	<% =Html.Password( "NewPassword", new { size = 32 } ) %>
	</div>

	<div>
	<label for="NewPasswordConfirm">Confirm New Password</label>
	<% =Html.Password( "NewPasswordConfirm", new { size = 32 } ) %>
	</div>

	<div><% =Html.SubmitButton( "Change Password" ) %></div>

</fieldset>
<% } %>

</asp:Content>
